<?php $this->_extends('_layouts/main_layout'); ?>
<?php $this->_block('resource'); ?>
	<script type="text/javascript" src="<?php echo JS_DIR; ?>imgpreview.full.0.22.jquery.js"></script>
<?php $this->_endblock(); ?>
<?php $this->_block('title'); ?>
	Blue Bar - Offer
<?php $this->_endblock(); ?>

<?php $this->_block('contents'); ?>

<div id="content" class="box">
	<h1>Blue Bar - Offer</h1>
	<div id="menu" class="box">
		<ul class="box">
			<li><a href="<?php echo url('bluebaroffer/add');?>"><span>Add</span></a></li>
		</ul>
	</div>
	<?php if (isset($infos)) 
			{
				foreach ($infos as $info)
				{
	?>
			<p class="msg info"><?php echo $info;?></p>
	<?php		}
			}
	?>
	<fieldset>
		<legend>Blue Bar - Offer</legend>
		<table class="full-size" style="text-align: center;">
			<thead>
				<tr>
					<th style="width:10%">Site</th>
					<th style="width:10%">Partner Name</th>
					<th style="width:20%">Offer Text</th>
					<th style="width:5%">Credit</th>
					<th style="width:20%">Link</th>
					<th style="width:15%">Order</th>
					<th style="width:10%">Operate</th>
				</tr>
			</thead>
			<tbody>
				<?php 
					if ($blueBarOffers && count($blueBarOffers) > 0):
						foreach($blueBarOffers as $offerBarOffer): 
				?>
					<tr>
						<td><?php echo $sites[$offerBarOffer['site_id']]; ?></td>
						<td>
							<?php echo (isset($offerBarOffer['is_partial']) && $offerBarOffer['is_partial'] == 1)? '(Partial)' : ''; ?>
							<?php echo $offerBarOffer['partner_name'];?>
						</td>
						<td><?php echo $offerBarOffer['offer_text']; ?></td>
						<td><?php echo $offerBarOffer['credit'];?></td>
						<td><?php echo $offerBarOffer['link'];?></td>
						<td>
							<input style="width:20px;" type="button" class="subOrdBtn" value="-" />
							<span id="<?php echo $offerBarOffer['id']; ?>"><?php echo $offerBarOffer['ord'];?></span>
							<input style="width:20px;" type="button" class="addOrdBtn" value="+" />
						</td>
						<td>
							<a href="<?php echo url('bluebaroffer/update', array('id'=>$offerBarOffer['id']));?>">Edit</a>&nbsp;&nbsp;&nbsp;&nbsp;
							<a href="<?php echo url('bluebaroffer/delete', array('id'=>$offerBarOffer['id']));?>">Delete</a>&nbsp;&nbsp;&nbsp;&nbsp;
							<a href="<?php echo url('bluebaroffer/pause', array('id'=>$offerBarOffer['id']));?>"><?php echo ($offerBarOffer['pause'] == 1)? 'Start':'Pause';?></a>
						</td>
					</tr>
				<?php 
						endforeach; 
					endif;
				?>
			</tbody>
		</table>
	</fieldset>
</div>

<script type="text/javascript">
	function changeOrd(numSpan, id, addSub)
	{
		$.ajax({
			type: 'post',
			url: '<?php echo url('bluebaroffer/changeOrd'); ?>',
			data: {btn: addSub, bid: id},
			success: function(rdata){
				if(rdata != 'false'){
					numSpan.html(rdata);
				}
			}
		});		
	}

	$('.subOrdBtn').click(function(){
		var span = $(this).parent().children('span');
		var id = span.attr('id');
		changeOrd(span, id, 'sub');
	});

	$('.addOrdBtn').click(function(){
		var span = $(this).parent().children('span');
		var id = span.attr('id');
		changeOrd(span, id, 'add');
	});
</script>

<?php $this->_endblock(); ?>